Coral-Trino: Migrate UDF operator transformers based on JSON-infra into transformers based on native Java code#355
Coral-Trino: Migrate UDF operator transformers based on JSON-infra into transformers based on native Java code#355yiqiangin wants to merge 1 commit intolinkedin:masterfrom yiqiangin:json-transformer-migration
Conversation
…rs based on native Java code
There was a problem hiding this comment.
Thanks @yiqiangin for this PR!
Please add the test part in the PR description.
| * matches the target values in the condition function. | ||
| */ | ||
| public abstract class SourceOperatorMatchSqlCallTransformer extends SqlCallTransformer { | ||
| public static final SqlOperator TIMESTAMP_OPERATOR = |
| } | ||
| }; | ||
|
|
||
| protected final SqlOperator DATE_OPERATOR = new SqlUserDefinedFunction(new SqlIdentifier("date", SqlParserPos.ZERO), |
There was a problem hiding this comment.
Can be static, should be aligned with TIMESTAMP_OPERATOR above.
| // math functions | ||
| new OperatorRenameSqlCallTransformer(SqlStdOperatorTable.RAND, 0, "RANDOM"), | ||
| new JsonTransformSqlCallTransformer(SqlStdOperatorTable.RAND, 1, "RANDOM", "[]", null, null), | ||
| new RandomOperatorWithOneOperandTransformer(), |
There was a problem hiding this comment.
Can we just use OperatorRenameSqlCallTransformer for this case?
| List<SqlNode> newOperands = new ArrayList<>(); | ||
| newOperands.add(sqlCall.getOperandList().get(1)); | ||
| return createCall(TARGET_OPERATOR, newOperands, SqlParserPos.ZERO); |
There was a problem hiding this comment.
Can be simplified to return TARGET_OPERATOR.createCall(sqlCall.getParserPosition(), sqlCall.getOperandList().get(1));, and many similar parts can be simplified in this PR.
|
|
||
| /** | ||
| * This class is a subclass of {@link SourceOperatorMatchSqlCallTransformer} which transforms a Coral SqlCall of "date_add" | ||
| * operator with 2 operands into a Trino SqlCall of an operator named "date_add" |
There was a problem hiding this comment.
Please add examples for each transformer in the class javadoc.
| private static final SqlOperator HIVE_PATTERN_TO_TRINO_OPERATOR = | ||
| new SqlUserDefinedFunction(new SqlIdentifier("hive_pattern_to_trino", SqlParserPos.ZERO), | ||
| FunctionReturnTypes.STRING, null, OperandTypes.STRING, null, null); |
There was a problem hiding this comment.
Can we just use createSqlOperator? Feel that the operand type is not necessary here.
In order to migrate all the transformers in which any of operatorTransformer, operandTransformer and resultTransformer is defined as a JSON string into the transformers which define the transformation rule in native Java code, the following code changes are made in this PR:
Adding some classes to implement the transformers which extends
SourceOperatorMatchSqlCallTransformerand the specific transformation logic is defined as native Java code includingRemoving the code of
JsonSqlCallTransformerTo be noted that this is the replacement of PR #350